#ifndef _LIB_UTIL_H
#define _LIB_UTIL_H

#include <sys/timeb.h>
#include <list>
#include <map>
#include <functional>
#include <string>
using namespace std;

#ifndef _WINDOWS
#define P2P_DAEMON_SERVER
#endif

#define LIB_UTIL_NAMESPACE			LibUtil
#define LIB_UTIL_NAMESPACE_BEGIN	namespace LIB_UTIL_NAMESPACE {
#define LIB_UTIL_NAMESPACE_END		}
#define USING_LIB_UTIL				using namespace LIB_UTIL_NAMESPACE;

#ifndef SAFE_DELETE
#define SAFE_DELETE(o) if(o) delete (o); (o) = NULL
#endif

#ifndef SAFE_DELETE_ARRAY
#define SAFE_DELETE_ARRAY(o) if(o) delete[] (o); (o) = NULL
#endif 

#ifndef SAFE_FREE
#define SAFE_FREE(o) if(o) free(o); (o) = NULL
#endif 

#ifndef SAFE_RELEASE
#define SAFE_RELEASE(o) if(o) { o->release(); delete o; }
#endif

typedef unsigned char byte;

#ifndef NULL
#define NULL 0
#endif

#ifdef _WINDOWS
#define atoll _atoi64
#endif

LIB_UTIL_NAMESPACE_BEGIN

struct tDataBuffer {
	byte* data;
	size_t size;
	size_t pos;

	tDataBuffer(bool refData = false);
	tDataBuffer(char* szText, bool refData = true);
	tDataBuffer(byte* inData, size_t dataSize, bool refData = true);
	tDataBuffer(const string& text, bool refData = true);
	tDataBuffer(const tDataBuffer& buffer, bool refData = false);
	~tDataBuffer();
	const tDataBuffer& operator = (const tDataBuffer& buffer);
	void Release();
	string ToString();
private:
	const bool ref;
};

LIB_UTIL_NAMESPACE_END

#include "LibUtil/ConnectionManager.h"
#include "LibUtil/EncodingHelper.h"
#include "LibUtil/EncryptHelper.h"
#include "LibUtil/MD5HashHelper.h"
#include "LibUtil/GeneralHashFunctions.h"
#include "LibUtil/CertHelper.h"

#endif //_LIB_UTIL_H


